<template>
  <div style="padding: 10px" class="maintable">
    <!--    功能区域-->
    <div>
      <el-button type="primary" @click="add">研学调换</el-button>

    </div>

    <!--    搜索区域-->
    <div style="margin: 10px 0">
<!--      <el-input class="inputPhone" v-model="search" placeholder="请输入关键字" style="width: 20%" clearable></el-input>-->
<!--      <el-button type="primary" style="margin-left: 5px" @click="load">查询</el-button>-->
      <div class="inputPhone">
        <div>
          <el-date-picker v-model="search" type="date" placeholder="选择日期"  format="YYYY-MM-DD"  value-format="YYYY-MM-DD">
          </el-date-picker>
          <el-button type="primary"  style="margin-left:5px">查询</el-button>
        </div>
      </div>
    </div>
    <el-table
        class="el-table-s"
        :data="tableData"
        border
        stripe
        style="width: 83.2% "
        >
      <el-table-column
          prop="id"
          label="ID"
          width="60"
          
          sortable
      >
      </el-table-column>
      <el-table-column
          width="100"
          prop="nameStudent"
         
          label="姓名">
      </el-table-column>
      <el-table-column
          width="160"
          prop="studyPlace"
          label="研学地点"
          sortable
      >
      </el-table-column>
      <el-table-column
          prop="dateOld"
          width="160"
          label="调前日期"
          sortable>
      </el-table-column>
      <el-table-column
          prop="sectionOld"
          width="100"
          label="调前节数"
          >
      </el-table-column>
      <el-table-column
          prop="dateNew"
          width="160"
          label="调后日期"
          sortable>
      </el-table-column>
      <el-table-column
          prop="sectionNew"
          width="100"
          label="调后节数"
          >
      </el-table-column>
      <el-table-column
          prop="reason"
          width="160"
          label="原因">
      </el-table-column>
       <el-table-column
          prop="dateNow"
          width="160"
          label="操作时间">
      </el-table-column>
      <el-table-column
          prop="moveNumber"
          label="本周调研学次数"
          width="120">
      </el-table-column>
      <el-table-column label="操作" width="160">
        <template #default="scope">
          <el-button size="mini" @click="handleEdit(scope.row)">编辑</el-button>
          <el-popconfirm title="确定删除吗？" @confirm="handleDelete(scope.row.id)">
            <template #reference>
              <el-button size="mini" type="danger">删除</el-button>
            </template>
          </el-popconfirm>
        </template>
      </el-table-column>
    </el-table>

    <div style="margin: 10px 0">
      <el-pagination
          @size-change="handleSizeChange"
          @current-change="handleCurrentChange"
          :current-page="currentPage"
          :page-sizes="[5, 10, 20]"
          :page-size="pageSize"
          layout="total, sizes, prev, pager, next, jumper"
          :total="total">
      </el-pagination>

      <el-dialog title="研学调换" v-model="dialogVisible" width="60%">
        <el-form :model="form" label-width="41%">
          <el-form-item label="姓名">
            <el-input v-model="form.nameStudent" style="width: 80%"></el-input>
          </el-form-item>
          <el-form-item label="研学地点 ">
            <el-input v-model="form.studyPlace" style="width: 80%" placeholder=" 格式： 数港/逸庐/行知"></el-input>
          </el-form-item>
          <el-form-item label="调整前日期 ">
            <el-input v-model="form.dateOld" style="width: 80%" placeholder=" 格式： 2022-11-15"></el-input>
          </el-form-item>
          <el-form-item label="调整前研学节数">
            <el-input v-model="form.sectionOld" style="width: 80%" placeholder=" 格式：第三节"></el-input>
          </el-form-item>
          <el-form-item label="调整后日期 ">
            <el-input v-model="form.dateNew" style="width: 80%" placeholder=" 格式： 2022-11-15 "></el-input>
          </el-form-item>
          <el-form-item label="调整后研学节数">
            <el-input v-model="form.sectionNew" style="width: 80%" placeholder=" 格式：第三节"></el-input>
          </el-form-item>
          <el-form-item label="原因">
            <el-input type="textarea" v-model="form.reason" style="width: 80%"></el-input>
          </el-form-item>
        </el-form>
        <template #footer>
          <span class="dialog-footer">
            <el-button @click="dialogVisible = false">取 消</el-button>
            <el-button type="primary" @click="save">确 定</el-button>
          </span>
        </template>
      </el-dialog>
    </div>
  </div>
</template>
<script>


import request from "@/utils/request";

export default {
  name: 'Move',
  components: {},
  data() {
    return {
      form: {},
      dialogVisible: false,
      search: '',
      currentPage: 1,
      pageSize: 10,
      total: 0,
      tableData: []
    }
  },
  created() {
    this.load()
  },
  methods: {
    load() {
      request.get("/moveStudy", {
        params: {
          pageNum: this.currentPage,
          pageSize: this.pageSize,
          search: this.search
        }
      }).then(res => {
        console.log(res)
        this.tableData = res.data.records
        this.total = res.data.total
      })
    },
    add() {
      this.dialogVisible = true
      this.form = {}
    },
    save() {
      if (this.form.id) {  // 更新
        request.put("/moveStudy", this.form).then(res => {
          console.log(res)
          if (res.code === '0') {
            this.$message({
              type: "success",
              message: "更新成功"
            })
          } else {
            this.$message({
              type: "error",
              message: res.msg
            })
          }
          this.load() // 刷新表格的数据
          this.dialogVisible = false  // 关闭弹窗
        })
      } else {  // 新增
        request.post("/moveStudy", this.form).then(res => {
          console.log(res)
          if (res.code === '0') {
            this.$message({
              type: "success",
              message: "新增成功"
            })
          } else {
            this.$message({
              type: "error",
              message: res.msg
            })
          }

          this.load() // 刷新表格的数据
          this.dialogVisible = false  // 关闭弹窗
        })
      }

    },
    handleEdit(row) {
      this.form = JSON.parse(JSON.stringify(row))
      this.dialogVisible = true
    },
    handleDelete(id) {
      console.log(id)
      request.delete("/moveStudy/" + id).then(res => {
        if (res.code === '0') {
          this.$message({
            type: "success",
            message: "删除成功"
          })
        } else {
          this.$message({
            type: "error",
            message: res.msg
          })
        }
        this.load()  // 删除之后重新加载表格的数据
      })
    },
    handleSizeChange(pageSize) {   // 改变当前每页的个数触发
      this.pageSize = pageSize
      this.load()
    },
    handleCurrentChange(pageNum) {  // 改变当前页码触发
      this.currentPage = pageNum
      this.load()
    }
  }
}
</script>
<style>
.maintable{
  width: 90%;
}
.el-dialog {
  width: 40%;
}

@media screen and (max-width: 768px) {
  .el-dialog {
    width: 90% !important;
  }
.el-table{
    height: 450px !important;
    overflow: auto !important;
  }
  .el-pagination__sizes {
    position: absolute;
    margin-top: 30px;
    left: 5px;
  }

  .el-form-item__label {
    font-size: 10px !important;
  }

  .inputPhone {
    width: 130px !important;
  }

  /* .el-input__inner {
    padding: 2px !important;
  } */

  .dialog-footer {
    width: 50px !important;
    min-width: 50px !important;
  }

  .maintable{
    width: 100% !important;
  }
  .el-button{
  margin-top: 5px  !important;
}

}

.cell {
  padding: 0 !important;
  text-align: center;
}

.el-textarea__inner {
  height: 32px !important;
}


.el-table-s {
  width: 81.2% ;
}
.el-table{
  max-height: 490px !important;
    overflow: auto !important;
}
/* 设置滚动条的样式 */
::-webkit-scrollbar {
  width: 8px;
  height:12px;
}
/* 滚动槽 */
::-webkit-scrollbar-track {
    -webkit-box-shadow: inset 0 0 6px rgba(255, 255, 255, 0.897);
    border-radius: 0px;
}
/* 滚动条滑块 */
::-webkit-scrollbar-thumb {
    border-radius:10px;
    background: #dbdff3;
    -webkit-box-shadow: inset 0 0 6px #dbdff3;
}
::-webkit-scrollbar-thumb:window-inactive {
    background: #dbdff3;
}
html,body{
  overflow: hidden;
}
</style>